package com.example.javamaday.offer;

import java.util.Comparator;
import java.util.PriorityQueue;

public class GetOffer59II {

    public static void main(String[] args) {

    }


    static class KthLargest {

        private PriorityQueue<Integer> priorityQueue;
        private int k;

        public KthLargest(int k, int[] nums) {
            this.k = k;
            this.priorityQueue = new PriorityQueue<>(k);
            for (int i = 0; i < nums.length; i++) {
                add(nums[i]);
            }
        }

        public int add(int val) {
            priorityQueue.offer(val);
            if (priorityQueue.size() > k) {
                priorityQueue.poll();
            }
            return priorityQueue.peek();
        }

    }



}
